package com.recharge.controller.callback;

import com.recharge.OrderService;
import com.recharge.domain.TradeFlow;
import com.recharge.domain.TradeOrder;
import com.recharge.mapper.ITradeFlowMapper;
import com.recharge.mapper.ITradeOrderMapper;
import com.recharge.sup.AbsSupChargeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author qq
 *
 */
@Controller
@RequestMapping("/yunLiuLiangBenFen")
public class YunLiuLiangBeiFenCallBackController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ITradeOrderMapper iTradeOrderMapper;

    @Autowired
    private ITradeFlowMapper iTradeFlowMapper;

    @Autowired
    private OrderService orderService;

    @Resource(name = "yunLiuLiangBeiFenChargeServiceImpl")
    private AbsSupChargeService absSupChargeService;

    @RequestMapping("/callback")
    @ResponseBody
    public String yunLiuLiang(@RequestParam("serialId")String serialId,
                              @RequestParam("errorCode")String errorCode,
                              @RequestParam("supplierSerialid")String supplierSerialid){
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("serialId", serialId);
        paramMap.put("errorCode", errorCode);
        paramMap.put("supplierSerialid", supplierSerialid);

        logger.info("orderID:{},收到结果回调,code:{}",serialId,errorCode);

        TradeFlow tradeFlow = iTradeFlowMapper.selectBySerId(serialId);
        TradeOrder tradeOrder =iTradeOrderMapper.selectByOrderId(tradeFlow.getOrderId());
        absSupChargeService.response(tradeOrder,tradeFlow,paramMap);

        return "ok";
    }
}
